package com.sanyue.dualPointer;

import org.junit.Test;

/**
 * @author sanyue
 * @version 1.0
 * @description: TODO-11
 * @date 2022/1/23 下午2:13
 */
public class ContainerWithMostWater {

    @Test
    public void solve(){
        int i = maxArea(new int[]{1,8,6,2,5,4,8,3,7});
        System.out.println("i:" + i);
    }
    //4 ms 在所有 Java 提交中击败了67.20%的用户
    public int maxArea(int[] height) {
        int ans = 0;
        int left = 0,right = height.length-1;
        while (left < right) {
            int temp = (height[left] < height[right] ? height[left] : height[right]) * (right - left);
            ans = Math.max(ans, temp);
            if (height[left] <= height[right]) left++;
            else right--;
        }
        return ans;
    }
}
